import { ZUSTAND_STORAGE } from '@/zustand'
import { create } from 'zustand'
import { persist } from 'zustand/middleware'

/** 👇 存储 user 相关信息 👇 */
const useUserInfo = create<ZUSTAND.IUserInfo>()(
  persist(
    (set) => ({
      token: '',
      setToken: (token) => set(() => ({ token })),
      userInfo: {},
      setUserInfo: (userInfo) => set(() => ({ userInfo })),
      userMenus: [],
      setUserMenus: (userMenus) => set(() => ({ userMenus })),
      menuSelectedKeys: [],
      setMenuSelectedKeys: (menuSelectedKeys) => set(() => ({ menuSelectedKeys })),
      clear: () => set(() => ({ token: '', userInfo: {}, userMenus: [], menuSelectedKeys: [] })),
    }),
    { storage: ZUSTAND_STORAGE, name: 'zustand_user_info' }
  )
)

export default useUserInfo
